﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Xml;
using System.IO;

namespace ThingyCloud
{
	class Globals
	{
		public static readonly int ScreenWidth = 1264;//640;
		public static readonly int ScreenHeight = 480;

		/// <summary>
		/// Transform an absolute coordinate between 0..ScreenWidth to the relative counter value
		/// </summary>
		public static double ToRelX(int val)
		{
			return Math.Round((double)val / Globals.ScreenWidth, 8);
		}

		/// <summary>
		/// Transform an absolute coordinate between 0..ScreenHeight to the relative counter value
		/// </summary>
		public static double ToRelY(int val)
		{
			return Math.Round((double)val / Globals.ScreenHeight, 8);
		}

		/// <summary>
		/// Transform a relative coordinate between 0..1 to the absolute counter value
		/// </summary>
		public static int ToAbsX(double val)
		{
			return (int)Math.Round(val * (double)ScreenWidth);
		}

		/// <summary>
		/// Transform a relative coordinate between 0..1 to the absolute counter value
		/// </summary>
		public static int ToAbsY(double val)
		{
			return (int)Math.Round(val * (double)ScreenHeight);
		}

		public static double rad2deg(double rad)
		{
			return rad * (180 / Math.PI);
		}

		public static double deg2rad(double deg)
		{
			return deg * (Math.PI / 180);
		}

		public static int double2int(double number)
		{
			return System.Convert.ToInt32(number);
		}

		public static int string2int(string value)
		{
			int number;
			bool result = Int32.TryParse(value, out number);
			if (!result)
			{
				Console.WriteLine("Attempted conversion of '{0}' failed.", value);
				return 0;
			}
			return number;
		}

		/// <summary>
		/// Returns a simple string used as a separator in debug messages
		/// </summary>
		public static string Separator
		{
			get
			{
				return "==================================================";
			}
		}

		public static int Messageport
		{
			get
			{
				return Globals.string2int(XmlConnection.getInstance().getSetting("Messageport"));
			}
		}

		public static Hashtable AvatarList
		{
			get
			{
				return XmlConnection.getInstance().getAvatarList();
			}
		}

		public static Hashtable CreatureSettings
		{
			get
			{
				return XmlConnection.getInstance().getCreatureSettings();
			}
		}

		public static ArrayList ThingyList
		{
			get
			{
				return XmlConnection.getInstance().getThingyList();
			}
		}
	}
}
